﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Runtime.Serialization.Json;

namespace CustomControlPractice.Controls.DateSlotPicker
{
    public partial class DateSlotPicker : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var dataSource = new DataSource();
            var serializer = new DataContractJsonSerializer(typeof(DataSource));
            var memoryStream = new MemoryStream();
            serializer.WriteObject(memoryStream, dataSource);
            data.Value = Encoding.Default.GetString(memoryStream.ToArray());
        }
    }

    public class DataSource
    {
        private readonly List<DateTime> availableDates;
        private readonly List<Resource> resources;

        public DataSource()
        {
            availableDates = new List<DateTime>();
            for (int i = 1; i < 8; i++)
            {
                availableDates.Add(DateTime.Now.AddDays(i));
            }

            var resource1 = new Resource {Name = "DoctorA"};
            resource1.AvailableCount = new Dictionary<DateRange, int>
                                           {
                                               {new DateRange(DateTime.Now, DateTime.Now.AddDays(1)), 3},
                                               {new DateRange(DateTime.Now.AddDays(2), DateTime.Now.AddDays(3)), 1},
                                               {new DateRange(DateTime.Now.AddDays(3), DateTime.Now.AddDays(4)), 0}
                                           };
            resources = new List<Resource> {resource1};
        }

        public IEnumerable<DateTime> AvailableDates
        {
            get { return availableDates; }
        }

        public IEnumerable<Resource> Resources
        {
            get { return resources; }
        }

    }
}